package com.huawei.appmarket.service.externalapi.actions;

import android.content.Intent;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.secure.android.common.intent.SafeIntent;
import o.cjm;
import o.cjo;
import o.Logger;
import o.drj;
import o.dyo;
import o.dyr;
import o.dys.a;
import o.epr;

public class AppDetailAction extends dyr {
    private static final String APP_ID = "appId";
    private static final String APP_PACKAGENAME = "APP_PACKAGENAME";
    private static final String DETAIL_ACCESSID = "accessID";
    private static final String DETAIL_ID = "appDetailId";
    private static final String DETAIL_INITPARAM = "initParam";
    private static final String TAG = "AppDetailAction";

    public AppDetailAction(a aVar) {
        super(aVar);
    }

    public void onAction() {
        Intent intent = this.callback.getIntent();
        if (intent != null) {
            SafeIntent safeIntent = new SafeIntent(intent);
            String stringExtra = safeIntent.getStringExtra("thirdId");
            if (!TextUtils.isEmpty(stringExtra)) {
                epr.ˎ().ˎ(stringExtra);
            }
            dailyReport(stringExtra);
            stringExtra = handlerDetailActParma(safeIntent);
            if (stringExtra != null) {
                cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
                Request request = new Request();
                request.ˋ(stringExtra);
                request.ˎ(true);
                if ("com.huawei.appmarket.intent.action.AppDetail.withaccessID".equals(safeIntent.getAction())) {
                    Object stringExtra2 = safeIntent.getStringExtra(DETAIL_ACCESSID);
                    if (!TextUtils.isEmpty(stringExtra2)) {
                        request.ʽ(stringExtra2);
                    }
                    stringExtra = safeIntent.getStringExtra(DETAIL_INITPARAM);
                    if (!TextUtils.isEmpty(stringExtra)) {
                        request.ˋॱ(stringExtra);
                        dyo.ˏ(safeIntent.getStringExtra(APP_ID), stringExtra);
                    }
                }
                appDetailActivityProtocol.ˏ(request);
                this.callback.ˎ(new cjm("appdetail.activity", appDetailActivityProtocol), 0);
            } else {
                Logger.e(TAG, "can not start AppDetail");
            }
        }
        this.callback.finish();
    }

    private String handlerDetailActParma(SafeIntent safeIntent) {
        String action = safeIntent.getAction();
        if ("com.huawei.appmarket.intent.action.AppDetail".equals(action)) {
            return drj.ॱ(safeIntent.getStringExtra(APP_PACKAGENAME));
        }
        if ("com.huawei.appmarket.appmarket.intent.action.AppDetail.withid".equals(action)) {
            return drj.ˏ(safeIntent.getStringExtra(APP_ID));
        }
        if ("com.huawei.appmarket.intent.action.AppDetail.withaccessID".equals(action)) {
            return drj.ˏ(safeIntent.getStringExtra(APP_ID));
        }
        if ("com.huawei.appmarket.appmarket.intent.action.AppDetail.withdetailId".equals(action)) {
            String startWithDetailId = startWithDetailId(safeIntent);
            if (TextUtils.isEmpty(startWithDetailId)) {
                return safeIntent.getStringExtra("suggest_intent_data_id");
            }
            return startWithDetailId;
        } else if ("com.huawei.appmarket.appmarket.intent.action.AppDetail.withURL".equals(action) || "com.huawei.appmarket.appmarket.intent.action.AppDetail.withapp".equals(action)) {
            return startWithDetailId(safeIntent);
        } else {
            return null;
        }
    }

    private String startWithDetailId(SafeIntent safeIntent) {
        return safeIntent.getStringExtra(DETAIL_ID);
    }
}
